<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@page import="util.Info" %>
<%@page import="dao.CommDAO" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>病历预览</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link href="admin/css/admin.css" type="text/css" rel="stylesheet">
    <style>
        input {
            width: 100%;
            background: none;
            border: none;
        }

        .no-border {
            border: none;
        }

        .spacer {
            height: 20px;
        }

        @media print {
            .no-print {
                display: none;
            }
        }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<%
    CommDAO dao = new CommDAO();
    String ghno = request.getParameter("ghno");
    HashMap mm = dao.select("select g.id,g.tname,p.* from ghinfo g left join patient p on g.tname=p.tname where ghno='" + ghno + "'").get(0);
    HashMap map = dao.select("select * from zd where ghno='" + ghno + "'").get(0);
    String info = map.get("info").toString();
    String numinfo = map.get("numinfo").toString();
%>

<body>
<form name="f1">
    <input type="hidden" id="ghno" name="ghno" value="<%=map.get("ghno") %>">
    <table cellspacing="0" cellpadding="0" width="95%" align="center" border="0">
        <tr height="20">
            <td></td>
        </tr>
        <tr height="22">
            <td style="padding-left: 20px; font-weight: bold; color: #ffffff"
                align="middle" background="admin/images/title_bg2.jpg">病历详情
            </td>
        </tr>
        <tr bgcolor="#ecf4fc" height="12">
            <td></td>
        </tr>
        <tr height="20">
            <td></td>
        </tr>
    </table>

    <table cellspacing="1" cellpadding="2" width="80%" align="center" border="0" bgcolor="#cccccc">
        <tr bgcolor="#ffffff" align="center">
            <td>医疗机构</td>
            <td colspan="5">私人牙科诊所</td>
            <td>组织机构代码</td>
            <td colspan="3">51008702-X</td>
        </tr>
        <tr bgcolor="#ffffff" align="center">
            <td>姓名</td>
            <td><input type="text" id="tname" value="<%=mm.get("tname") %>" disabled></td>
            <td>性别</td>
            <td style="display: flex;">
                <%
                    if (mm != null && mm.get("sex") != null && mm.get("sex").equals("男")) {
                %>
                <input type="radio" name="sex" value="男" checked disabled>男
                <input type="radio" name="sex" value="女" disabled>女
                <%
                } else {
                %>
                <input type="radio" name="sex" value="男" disabled>男
                <input type="radio" name="sex" value="女" checked disabled>女
                <% } %>
            </td>
            <td>出生日期</td>
            <td><input type="text" id="birth" name="birth" value="<%=mm.get("birth") %>" disabled></td>
            <td>年龄</td>
            <td><input type="text" id="age" value="<%=mm.get("age") %>" disabled></td>
            <td>电话</td>
            <td><input type="text" id="phone" value="<%=mm.get("tel") %>" disabled></td>
        </tr>
        <tr bgcolor="#ffffff" align="center">
            <td>国籍</td>
            <td><input type="text" id="nationality" value="<%=mm.get("nationality") %>" disabled></td>
            <td>出生地</td>
            <td colspan="3"><input type="text" id="base" value="<%=mm.get("base") %>" disabled></td>
            <td>职业</td>
            <td><input type="text" id="occupation" value="<%=mm.get("occupation") %>" disabled></td>
            <td>婚姻状况</td>
            <td><input type="text" id="marital_status" value="<%=mm.get("marital_status") %>" disabled></td>
        </tr>
        <tr bgcolor="#ffffff" align="center">
            <td>身份证号</td>
            <td colspan="7"><input type="text" id="id_number" value="<%=mm.get("idcard") %>" disabled></td>
            <td>民族</td>
            <td><input type="text" id="nation" value="<%=mm.get("nation") %>" disabled></td>
        </tr>
        <tr bgcolor="#ffffff" align="center">
            <td>现住址</td>
            <td colspan="9"><input type="text" id="current_address" value="<%=mm.get("addr") %>" disabled>
            </td>
        </tr>
        <tr bgcolor="#ffffff" align="center">
            <td>户口地址</td>
            <td colspan="9"><input type="text" id="registered_address" value="<%=mm.get("registered_address") %>"
                                   disabled></td>
        </tr>
        <tr bgcolor="#ffffff" align="center">
            <td>病情</td>
            <td colspan="9"><input type="text" id="bq" name="bq" value="<%=map.get("bq") %>" disabled></td>
        </tr>
        <tr bgcolor="#ffffff" align="center">
            <td>诊断</td>
            <td colspan="9"><input type="text" id="zd" name="zd" value="<%=map.get("zd") %>" disabled></td>
        </tr>
        <%--        <tr bgcolor="#ffffff" align="center">
                    <td>治疗方案</td>
                    <td colspan="9"><input type="text" id="treatment_plan" value="<%=map.get("treatment_plan") %>" disabled>
                    </td>
                </tr>--%>
        <tr bgcolor="#ffffff" align="center">
            <td>药品、处置：</td>
            <td colspan="9">
                <%
                    String yinfo = "";
                    String[] a = info.split("\\$");
                    String[] b = numinfo.split("\\$");
                    for (int i = 0; i < a.length; i++) {
                        yinfo += a[i] + "&nbsp;&nbsp;数量:" + b[i] + "<br/>";
                    }
                %>
                <%=yinfo %>
            </td>
        </tr>
        <tr bgcolor="#ffffff" align="center">
            <td>主治医生</td>
            <td colspan="4"><input type="text" id="doctor" value="<%=map.get("oper") %>" disabled></td>
            <td>总费用</td>
            <td colspan="4">
                <%
                    DecimalFormat decimal = new DecimalFormat("#.#");
                    String totalprice = "0.0"; // 默认值
                    if (map != null && map.get("totalprice") != null) {
                        try {
                            totalprice = decimal.format(Double.valueOf(map.get("totalprice").toString()));
                        } catch (NumberFormatException e) {
                            // 处理异常，例如记录日志或给出默认值
                            totalprice = "0.0";
                        }
                    }
                %>
                <%=totalprice %>元
            </td>
        </tr>
        <tr bgcolor="#ffffff" align="center">
            <td class="no-border spacer" colspan="10"></td>
        </tr>
        <tr class="no-print" bgcolor="#ffffff" align="center">
            <td class="no-border spacer" colspan="10">
                <button type="button" onclick="enableEdit()">编辑</button>
                <button type="button" onclick="saveEdit()">保存</button>
                <button type="button" onclick="javascript:window.print();">打印</button>
            </td>
        </tr>
    </table>
</form>
</body>
<script type="text/javascript">
    function enableEdit() {
        $("input[type='text'], input[type='radio']").prop('disabled', false);
    }

    function saveEdit() {
        var data = {};
        $("input[type='text'], input[type='radio']:checked").each(function () {
            data[this.id] = this.value;
        });
        data['ghno'] = $('#ghno').val();
        $.ajax({
            url: '/srykzsblmis/studysite?ac=pantinerUpdate',
            type: 'POST',
            data: data,
            success: function (response) {
                alert('保存成功');
                $("input[type='text'], input[type='radio']").prop('disabled', true);
            },
            error: function () {
                alert('保存失败');
            }
        });
    }

    function preview(oper) {
        if (oper < 10) {
            var bdhtml = window.document.body.innerHTML; //获取当前页的html代码
            var sprnstr = "<!--startprint" + oper + "-->"; //设置打印开始区域
            var eprnstr = "<!--endprint" + oper + "-->"; //设置打印结束区域
            var prnhtml = bdhtml.substring(bdhtml.indexOf(sprnstr) + 18); //从开始代码向后取html
            prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr)); //从结束代码向前取html
            window.document.body.innerHTML = prnhtml;
            window.print();
            window.document.body.innerHTML = bdhtml;
        } else {
            window.print();
        }
    }
</script>
</html>
